<template>
  <dialog-editor ref="dialog" :width="60"> </dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'
export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        neckRingName: {
          label: '肩套名称',
          placeholder: '请输入肩套名称'
        },
        neckRingDesc: {
          label: '规格描述'
        },
        neckRingType: {
          label: '肩套类别'
        },
        bottleOutDiameter: {
          label: '口径',
        },
        neckRingColor: {
          label: '颜色'
        },
        neckRingMaterial: {
          label: '材质',
        },
        relateLevel: {
          label: '等级',
        },
        relateImageInfo: {
          label: '图片信息',
          type: 'uploadScreenshot',
          imageType: 'uploadProductImage'
        },
        remark: {
          label: '备注'
        }
      }
    }
  },
  methods: {
    init(id, property, cb) {
      this.dataForm.id = id || 0

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('proofingName','modelId','unitPrice', 'number','calibrator','clientId', 'weight','bottleLength','bottleWeight','bottleHeight', 'proofingTime', 'localProduct', 'productDrawingId','status'),
        initApi: 'relateApi/getRelateNeckRingInfoInfo',
        saveApi: 'relateApi/saveRelateNeckRingInfo',
        updateApi: 'relateApi/updateRelateNeckRingInfo',
        objectName: 'relateNeckRingInfo',
        submitCallback: cb,
      })
      this.$nextTick(() => {

        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    },
    addNewClientInfo(){
      const cb = (newValue) => {
        this.initClientInfoList()
        this.dataForm.clientId = newValue.id
      }
      this.$parent.openClientInfoDialog(cb)
    },
    addNewModelInfo(){
      const cb = (newValue) => {
        this.initModelInfoList()
        this.dataForm.modelId = newValue.id
      }
      this.$parent.openModelInfoDialog(cb)
    },
    modelIdSelectCallback() {

      mRequest('orderApi/getOrderProofingByModelId', {modelId: this.dataForm.modelId}, (res) => {
        const {data} = res
        const {orderProofing} = data
        const {bottleLength,bottleWeight,bottleHeight} = orderProofing
        this.dataForm.bottleLength = bottleLength
        this.dataForm.bottleWeight = bottleWeight
        this.dataForm.bottleHeight = bottleHeight
      })
    },
  }
}
</script>
